1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.apache.tapestry5.integration.pagelevel;
16
17 import org.apache.tapestry5.dom.Document;
18 import org.apache.tapestry5.test.PageTester;
19 import org.testng.Assert;
20 import org.testng.annotations.DataProvider;
21 import org.testng.annotations.Test;
22
23 public class DTDTest extends Assert
24 {
25 private static final String FRAMESET = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">";
26
27 private static final String TRANSITIONAL = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
28
29 private static final String STRICT = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
30
31 @DataProvider
32 public Object[][] dtd_page_provider()
33 {
34 return new Object[][]
35 {
36 { "DTDFromPage", FRAMESET, "slagheap", },
37 { "DTDFromComponent", TRANSITIONAL, "flubber", },
38 { "MultipleDTD", STRICT, "blubber", },
39 { "NoDTD", "", "no_dtd_loser", } };
40 }
41
42 @Test(dataProvider = "dtd_page_provider")
43 public void verify_correct_dtds(String pageName, String expectedDTD, String checkText)
44 {
45 PageTester tester = new PageTester(TestConstants.APP2_PACKAGE, TestConstants.APP2_NAME);
46
47 Document doc = tester.renderPage(pageName);
48 String txt = doc.toString();
49
50 assertTrue(txt.startsWith(expectedDTD));
51
52 checkOtherDTD(txt, expectedDTD);
53
54
55 assertTrue(txt.contains(checkText));
56
57 }
58
59 private void checkOtherDTD(String txt, String expected)
60 {
61 if (expected.equals(TRANSITIONAL))
62 {
63 check(txt, FRAMESET, STRICT);
64 }
65 else if (expected.equals(FRAMESET))
66 {
67 check(txt, STRICT, TRANSITIONAL);
68 ;
69 }
70 else if (expected.equals(STRICT))
71 {
72 check(txt, FRAMESET, TRANSITIONAL);
73 }
74 else if (expected.equals(""))
75 {
76 check(txt, FRAMESET, STRICT, TRANSITIONAL);
77 }
78 else
79 {
80 throw new RuntimeException("Unknown expected string: " + expected);
81 }
82 }
83
84 private void check(String txt, String... invalids)
85 {
86 for (String invalid : invalids)
87 {
88 assertFalse(txt.contains(invalid));
89 }
90 }
91
92 }